package lu.med.praxiswahl.wahlumed.client.kalender;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;

/**
 * 
 * @author Lars Holger Roth
 */
public class WochenplanRenderer implements TableCellRenderer
{

    private Color black = new Color(0, 0, 190);
    private Color white = new Color(255, 255, 255);
    private Color red = new Color(255, 0, 0);
    private Color grey = new Color(200, 200, 200);
    private Color yellow = new Color(200, 200, 0);
    private Font bold = new Font("Arial", Font.BOLD, 12);
    private WochenplanTableModel model;

    public WochenplanRenderer(WochenplanTableModel model)
    {
	this.model = model;
    }

    public Component getTableCellRendererComponent(JTable table, Object value,
	    boolean isSelected, boolean hasFocus, int row, int column)
    {
	// Wenn die Menge des Artikels knapp ist, so wird die entsprechende
	// Zeile Wei� auf Rot dargestellt, ansonsten Schwarz auf Wei�
	JLabel label = new JLabel();

	label.setOpaque(true);
	Border b = BorderFactory.createEmptyBorder(1, 1, 1, 1);
	label.setBorder(b);
	label.setFont(table.getFont());

	if ((row % 4 == 0) || (row == 0))
	{
	    label.setForeground(table.getForeground());
	    label.setBackground(grey);
	}
	else
	{
	    // Jede zweite Zeile bekommt grauen Hintergrund
	    label.setForeground(table.getForeground());
	    label.setBackground(table.getBackground());
	}
	// Sonderf�lle f�r die Farben
	label.setText((String) model.getValueAt(row, column));

	if (label.getText().equals("1.GUS"))
	{
	    label.setBackground(yellow);
	}
	else if (label.getText().equals("AC"))
	{
	    label.setBackground(red);
	    label.setForeground(white);
	    label.setFont(bold);
	}
	else if (label.getText().equals("NUS"))
	{
	    label.setBackground(yellow);
	}
	else if (label.getText().equals("IOP"))
	{
	    label.setBackground(yellow);
	}

	if (hasFocus)
	{
	    label.setBackground(black);
	    label.setForeground(white);
	}
	else
	{
	    // Angezeigte Spalte in Modellspalte umwandeln
	    column = table.convertColumnIndexToModel(column);
	}

	return label;
    }
}
